package com.ruoyi.wechat.api;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wechat.domain.ScenicSpots;
import com.ruoyi.wechat.service.IScenicSpotsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value="微信小程序API-营地周边景点管理",tags={"微信小程序API-营地周边景点管理"})
@RestController
@RequestMapping("/wechat/spots")
public class WxScenicSpotsController extends BaseController {
    @Autowired
    private IScenicSpotsService scenicSpotsService;

    @ApiOperation(value = "添加周边景点")
    @Log(title = "微信小程序API-营地周边景点管理", businessType = BusinessType.INSERT)
    @PostMapping("/wxadd")
    public AjaxResult add(@RequestBody ScenicSpots spots) {
        return toAjax(scenicSpotsService.insertScenicSpots(spots));
    }


    @ApiOperation(value = "根据营地Id获取该营地下的周边景点列表", response = ScenicSpots.class)
    @GetMapping("/wxlist")
    public AjaxResult list(ScenicSpots spots) {
        List<ScenicSpots> list = scenicSpotsService.selectScenicSpotsList(spots);
        return success(list);

    }


    @ApiOperation(value = "根据周边景点Id查询详细信息", response = ScenicSpots.class)
    @GetMapping("/wxgetInfo/{scenicId}")
    public AjaxResult getInfo(@PathVariable("scenicId") String scenicId) {
        if (scenicId == null) {
            return error("周边景点Id不能为空");
        }
        return success(scenicSpotsService.selectScenicSpotsByScenicId(scenicId));
    }

    @ApiOperation(value = "根据周边景点Id完成删除")
    @Log(title = "微信小程序API-营地周边景点管理",businessType = BusinessType.DELETE)
    @DeleteMapping("/delete/{scenicId}")
    public AjaxResult delete(@PathVariable("scenicId") String scenicId) {
        if (scenicId == null) {
            return error("周边景点Id不能为空");
        }
        return toAjax(scenicSpotsService.deleteScenicSpotsByScenicId(scenicId));
    }
}
